The Tree Viewer is a debugging tool that shows the relationships between different objects in a program. It was primarily intended for people (like me) who are new to programming with Think C classes and may have trouble visualizing the visual hierarchy and the chain of command. It can show a tree with the subviews of a view, or the enclosures of a view, or the supervisors of a bureaucrat. Here is sample output:
For this illustration, I took the Starter project and created an object of type CTreeViewer called theViewer, and sent it the message ShowSubviews (gDesktop) to show the class names of all the subviews that are enclosed by the gDesktop. The program had three windows: the window enclosing the CStarterPane (on top), the window belonging to theViewer and the window belonging to the CClipboard (which was hidden).
Views drawn with rectangles want mouse clicks, while those drawn with rounded rectangles don’t. Views with bold outlines are active, while those with dotted lines are not visible.
Here is another example. Assume that we have the following dialog box:
Calling theViewer -> ShowSubViews (theDialog), we get the following tree:
[If the ID of a view is a resource ID or a text string, the Tree Viewer will display the ID (CDLOGDialog automatically assigns the panorama it creates the ID 'pano' and the dialog items ID’s equal to their DITL ID’s). This can be handy for debugging: when you create a view of your own, you can call theView->SetID().]
The class can also display the enclosures of a view. If we call theViewer -> ShowEnclosures() for one of the buttons in the above dialog box, we get:
Finally, it will show the supervisors of a bureaucrat. If we call theViewer -> ShowSupervisors() for the same button, we get the following:
Classes in rectangles are CViews, those in rounded rectangles are bureaucrats other than CViews. Objects drawn with thick borders can become the gGopher. To see the current chain of command pass gGopher as the argument to ShowSupervisors.
It would have been nice to be able to show the tree of bureaucrats starting at the top (the gApplication) to see all the possible chains of commands; however, bureaucrats only know their supervisors, not the objects that they supervise. Perhaps such features could be built into the debugger in the future.
For specific information on calling each routine read the comments in the CTreeViewer.c file.
Disclaimer: This was a simple program I put together to help me learn about the relationships between various object classes. There is almost certainly many ways of crashing this program (particularly if you put calls to it while views are changing or during non-reentrent Quickdraw code (such as when a picture is open)). Use at your own risk.